package com.haiersen.sign.attendance;

import java.util.Map;

import javax.ws.rs.DefaultValue;

import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.haiersen.sign.attendance.service.IAttendanceRecordService;
import com.haiersen.sign.common.ErrorType;
import com.haiersen.sign.utils.JSONUtil;

@Controller
@RequestMapping("/attendance")
public class AttendanceController {
	
	@Autowired
	private IAttendanceRecordService attendanceRecordService;
	
	@RequestMapping(value = "/record/add", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> add(
			@RequestParam("userId") @NotBlank String userId,
			@RequestParam("signEquipment") String signEquipment,
			@RequestParam("iBeaconId") @NotBlank String iBeaconId,
			@RequestParam("type") @DefaultValue("0") boolean type){
		attendanceRecordService.addAttendance(userId, signEquipment, iBeaconId, type);
		return JSONUtil.getJSON(ErrorType.SUCCESS);
		
	}
}
